# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=v4l-utils
pkgver=1.24.1
pkgrel=1
pkgdesc="Userspace tools and conversion library for Video 4 Linux"
url="https://linuxtv.org/"
arch="all"
license="LGPL-2.0-or-later"
makedepends="
	alsa-lib-dev
	argp-standalone
	eudev-dev
	libjpeg-turbo-dev
	linux-headers
	qt5-qtbase-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-dvbv5
	libdvbv5
	$pkgname-libs
	qv4l2
	ir_keytable
	"
source="https://linuxtv.org/downloads/v4l-utils/v4l-utils-$pkgver.tar.bz2
	types.patch
	"

case "$CARCH" in
arm*|aarch64)
	# no desktop opengl on arm, only es2
	;;
*)
	subpackages="$subpackages qvidcap"
	;;
esac

build() {
	export CFLAGS="$CFLAGS -O2 -flto=auto"
	export CXXFLAGS="$CXXFLAGS -O2 -flto=auto"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--enable-libdvbv5 \
		--disable-static
	make
}

check() {
	make check
}

package() {
	make -j1 DESTDIR="$pkgdir" install
	install -Dm644 "$builddir"/utils/qv4l2/qv4l2.desktop \
		"$pkgdir"/usr/share/applications/qv4l2.desktop
	install -Dm644 "$builddir"/utils/qv4l2/qv4l2.svg \
		"$pkgdir"/usr/share/icons/hicolor/scalable/apps/qv4l2.svg
}

qv4l2() {
	pkgdesc="QT v4l2 test control and streaming test application"

	amove usr/bin/qv4l2 \
		usr/share
}

qvidcap() {
	pkgdesc="v4l2 video capture viewer"

	amove usr/bin/qvidcap
}

dvbv5() {
	pkgdesc="Backwards compatible DVBv5 command line utilities"

	amove usr/bin/dvb*
}

libdvbv5() {
	pkgdesc="libdvbv5 library"

	amove usr/lib/libdvbv5.*
}

libs() {
	pkgdesc="Collection of video4linux support libraries"

	amove usr/lib
}

ir_keytable() {
	pkgdesc="Alter keymaps of Remote Controller devices"

	amove lib/udev \
		usr/bin/ir-keytable \
		etc/rc_maps.cfg
}

sha512sums="
1e82ba125285e875bf4a216adedab9147009e6af1aadd79a3a1770231d3c96ec29245b33e75f69a9ce1b25011e71746db242c778ac3369148de1e9de2e318663  v4l-utils-1.24.1.tar.bz2
358611fbae8348f17bf49c08820b4641deb1f7282ce2c1e20b8fdf0a85cd73ca4b46f6668c2a7328b5261e401c12f471170a9a1f3fc2982b6897ff11386c06c6  types.patch
"
